
package com.john.blog.controller.back;

import java.util.List;

import javax.annotation.PostConstruct;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.john.blog.common.utils.DetectUtils;
import com.john.blog.common.vo.CommonResult;
import com.john.blog.controller.back.support.AbstractBackModelControllerSupport;
import com.john.blog.model.po.Tags;
import com.john.blog.service.TagsService;

import tk.mybatis.mapper.entity.Example;

/**
 * 标签controller
 * 
 * @author JiangGengchao
 * @date 2018年2月25日
 */
@RestController
@RequestMapping("/blog/back/tag")
public class BackTagsController extends AbstractBackModelControllerSupport<Tags> {

    @Autowired
    private TagsService tagsService;

    @PostConstruct
    public void init() {
        this.service = tagsService;
    }

    @RequestMapping("/add")
    @Override
    public CommonResult add(Tags model) {
        Example example = new Example(Tags.class);
        example.createCriteria().andEqualTo("name", model.getName());
        List<Tags> tagsList = tagsService.selectByExample(example);
        if (DetectUtils.notEmpty(tagsList)) {
            return CommonResult.error("标签已存在");
        } else {
            return super.add(model);
        }
    }

}
